package com.saikuo.service.elasticsearch;

import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;

import java.net.UnknownHostException;

/**
 * Created by work on 2016/10/25.
 */
public class ElasticsearchHandler {

    public SearchHit[] searcher(QueryBuilder queryBuilder, String type, int from) throws UnknownHostException {
        SearchResponse searchResponse = ElasticsearchFactory.
                getTransportClient()
                .prepareSearch("yaoindex")
                .setTypes(type)
                .setQuery(queryBuilder)
                .setFrom(from)
                .setSize(20)
                .execute()
                .actionGet();
        SearchHits hits = searchResponse.getHits();
        return hits.getHits();
    }
}
